node-editor: Support pasting the image
authorMatthias Clasen <mclasen@redhat.com>
Sat, 3 Apr 2021 01:24:59 +0000 (21:24 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Sat, 3 Apr 2021 01:24:59 +0000 (21:24 -0400)
Add a button that copies the image to the clipboard.

demos/node-editor/node-editor-window.c
demos/node-editor/node-editor-window.ui

index 03da8c67bddaea3e3d2bc3256b58ccf4975bcc64..ce4198d68388930a3747cadb03d364faf82a6f0f 100644 (file)
@@ -635,6 +635,24 @@ export_image_cb (GtkWidget        *button,
   gtk_widget_show (dialog);
 }
 
+static void
+clip_image_cb (GtkWidget        *button,
+               NodeEditorWindow *self)
+{
+  GdkTexture *texture;
+  GdkClipboard *clipboard;
+
+  texture = create_texture (self);
+  if (texture == NULL)
+    return;
+
+  clipboard = gtk_widget_get_clipboard (GTK_WIDGET (self));
+
+  gdk_clipboard_set_texture (clipboard, texture);
+
+  g_object_unref (texture);
+}
+
 static void
 testcase_name_entry_changed_cb (GtkWidget        *button,
                                 GParamSpec       *pspec,
@@ -826,6 +844,7 @@ node_editor_window_class_init (NodeEditorWindowClass *class)
   gtk_widget_class_bind_template_callback (widget_class, open_cb);
   gtk_widget_class_bind_template_callback (widget_class, save_cb);
   gtk_widget_class_bind_template_callback (widget_class, export_image_cb);
+  gtk_widget_class_bind_template_callback (widget_class, clip_image_cb);
   gtk_widget_class_bind_template_callback (widget_class, testcase_save_clicked_cb);
   gtk_widget_class_bind_template_callback (widget_class, testcase_name_entry_changed_cb);
   gtk_widget_class_bind_template_callback (widget_class, dark_mode_cb);
index 73b8b9ce4bd7f0bdf86b2a39529890c4df025ebf..fc26719819e296b20eac663fcba2f7da8ab8a931 100644 (file)
           </object>
         </child>
         <child type="start">
-          <object class="GtkSeparator">
-            <property name="orientation">vertical</property>
+          <object class="GtkButton">
+            <property name="icon-name">edit-copy-symbolic</property>
+            <property name="tooltip-text">Copy image to clipboard</property>
+            <signal name="clicked" handler="clip_image_cb"/>
           </object>
         </child>
         <child type="start">